﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using Server_NhaSach.DataTransferObject;
using Server_NhaSach.DataAccess.HelperLayer;
namespace Server_NhaSach.DataAccess.LogicLayer
{
    public class CTDatHangNCCDAO
    {
        #region "Khai báo các biến"
        private Helper helper;
        private string _error;
        #endregion

        #region "Khai báo các thuộc tính"
        public string Error
        {
            get { return _error; }
        }
        #endregion

        #region "Khai báo các Method"
        public bool InsertCTDHNCC(CTDatHangNCCDTO CTDatHangNCC)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[8];
            par[0] = new SqlParameter("@MaMH", CTDatHangNCC.MaMH);
            par[1] = new SqlParameter("@MaDHNCC", CTDatHangNCC.MaDHNCC);
            par[2] = new SqlParameter("@SoLuong", CTDatHangNCC.SoLuong);
            par[3] = new SqlParameter("@DVT", CTDatHangNCC.DVT);
            par[4] = new SqlParameter("@DonGia", CTDatHangNCC.DonGia);
            par[5] = new SqlParameter("@ChietKhau", CTDatHangNCC.ChietKhau);
            par[6] = new SqlParameter("@ThanhTien", CTDatHangNCC.ThanhTien);
            par[7] = new SqlParameter("@DaGiao", CTDatHangNCC.DaGiao);
            try
            {
                helper.InsertQuery("sp_Insert_CTDatHangNCC", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public bool UpdateCTDHNCC(CTDatHangNCCDTO CTDatHangNCC)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[8];
            par[0] = new SqlParameter("@MaMH", CTDatHangNCC.MaMH);
            par[1] = new SqlParameter("@MaDHNCC", CTDatHangNCC.MaDHNCC);
            par[2] = new SqlParameter("@SoLuong", CTDatHangNCC.SoLuong);
            par[3] = new SqlParameter("@DVT", CTDatHangNCC.DVT);
            par[4] = new SqlParameter("@DonGia", CTDatHangNCC.DonGia);
            par[5] = new SqlParameter("@ChietKhau", CTDatHangNCC.ChietKhau);
            par[6] = new SqlParameter("@ThanhTien", CTDatHangNCC.ThanhTien);
            par[7] = new SqlParameter("@DaGiao", CTDatHangNCC.DaGiao);
            try
            {
                helper.UpdateQuery("sp_Update_CTDatHangNCC", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public bool DeleteCTDHNCC(string MaMH,string MaDHNCC)
        {
            helper = new Helper();
            SqlParameter[] par = new SqlParameter[2];
            par[0] = new SqlParameter("@MaMH", MaMH);
            par[1] = new SqlParameter("@MaDHNCC", MaDHNCC);
            try
            {
                helper.DeleteQuery("sp_Delete_CTDatHangNCC", par);
            }
            catch (Exception ex)
            {
                _error = helper.Error + " - " + ex.Message;
                return false;
            }
            return true;
        }
        public DataSet LayDS_CTDHNCC()
        {
            helper = new Helper();
            DataSet ds_CTDHNCC = helper.SelectQuery("sp_LayDS_CTDatHangNCC");
            return ds_CTDHNCC;
        }
        #endregion
    }
}